package com.njuse.jvmfinal.memory.jclass.runtimeConstantPool.constant.ref;

import com.njuse.jvmfinal.classloader.classfileparser.constantpool.info.MethodrefInfo;
import com.njuse.jvmfinal.memory.jclass.JClass;
import com.njuse.jvmfinal.memory.jclass.Method;
import com.njuse.jvmfinal.memory.jclass.runtimeConstantPool.RuntimeConstantPool;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MethodRef extends MemberRef {
    private Method method;

    public MethodRef(RuntimeConstantPool runtimeConstantPool, MethodrefInfo methodrefInfo) {
        super(runtimeConstantPool, methodrefInfo);
    }

    public Method findmethod() {
    	return findmethod(findclass());
    }
    
    public Method findmethod(JClass clazz) {
     	JClass t=clazz;
    	while (t!=null) {
    		Method[] methods=t.getMethods();
    		for (int i=0;i<methods.length;i++) {
    			if (methods[i].getDescriptor().equals(descriptor)&&methods[i].getName().equals(name)) {
    				return methods[i];
    			}
    		}
    		t=t.getSuperClass();
    	}
    	return null;
    }
}
